<template>
	<div class="login">
		<view class="logo"></view>
		<view class="welcome"> 欢迎使用 </view>
		<view class="loginText">登录</view>
		<view>
			<input class="inputStyle" placeholder="学号" v-model="formdata.username" />
		</view>
		<view>
			<input class="inputStyle" type="password" placeholder="密码" v-model="formdata.password" />
		</view>
		<view>
			<text class="floatLeft" @click="forget">忘记密码</text>
			<text class="floatRight" @click="register">立即注册</text>
		</view>
		<button type="default" class="loginBtn" @click="login">登录</button>
		<view class="footText">帮助及反馈</view>
	</div>
</template>


<script>
	const {login,getUser} = require('../../utils/api.js')
	export default {
		data() {
			return {
				loginUrl:"",
				formdata:{
					username:"",
					password:"",
					role:"01"
				}
			}
		},
		created() {
			
		},
		methods:{
			register(){
				uni.navigateTo({
					url: 'register'
				});
			},
			forget(){
				uni.navigateTo({
					url: 'forget'
				});
			},
			login(){
				login(this.formdata).then(data=>{
					uni.showModal({
						content: data.msg,
						showCancel: false
					});
					uni.setStorageSync('identity',data.msg);
					if(data.code === 200){
						getUser(this.formdata).then(data=>{
							uni.setStorageSync('stu',data.msg[0]);
						})
						uni.switchTab({
							url: '/pages/home/index'
						});
					}
				})
			}
			
		}
	}
</script>

<style scoped src="../../static/css/login.css"></style>
